mk_online_func_x <- function(cls, ...)
{
  new_name <- paste0(cls, "_new")
  run_name <- paste0(cls, "_run")
  new_func <- match.fun(new_name)
  run_func <- match.fun(run_name)

  ptr <- new_func(...)
  function(x)
  {
    run_func(ptr, x)
  }
}

mk_online_func_xw <- function(cls, ...)
{
  new_name <- paste0(cls, "_new")
  run_name <- paste0(cls, "_run")
  new_func <- match.fun(new_name)
  run_func <- match.fun(run_name)

  ptr <- new_func(...)
  function(x, w)
  {
    if (length(x) != length(w))
    {
      stop("Input lengths do not match.")
    }
    run_func(ptr, x, w)
  }
}

mk_aggr_time_func <- function(..., window, type, itime = FALSE)
{
  if (itime)
  {
    new_name <- paste0(window, "_", type, "_", itime, "_new")
    run_name <- paste0(window, "_", type, "_", itime, "_run")
  } else {
    new_name <- paste0(window, "_", type, "_new")
    run_name <- paste0(window, "_", type, "_run")
  }

  new_func <- match.fun(new_name)
  run_func <- match.fun(run_name)

  ptr <- new_func(...)
  function(time, price, volume, turnover)
  {
    run_func(ptr, time, price, volume, turnover)
  }
}

mk_aggr_quant_func <- function(..., clk, type)
{
  new_name <- paste0(clk, "_", type, "_new")
  run_name <- paste0(clk, "_", type, "_run")
  new_func <- match.fun(new_name)
  run_func <- match.fun(run_name)

  ptr <- new_func(...)
  function(price, volume, turnover)
  {
    run_func(ptr, price, volume, turnover)
  }
}

mk_aggr_bar <- function(..., type)
{
  new_name <- paste0(type, "_bar_new")
  run_name <- paste0(type, "_bar_run")
  new_func <- match.fun(new_name)
  run_func <- match.fun(run_name)

  ptr <- new_func(...)
  function(price, volume, turnover)
  {
    run_func(ptr, time, price, volume, turnover)
  }
}
